#ifndef _MY_MICRO_NUM_H_
#define _MY_MICRO_NUM_H_

#include "mytype.h"

#ifdef __cplusplus
extern "C"
{
#endif

#ifndef EXT_TRUE
#define EXT_TRUE 1
#define EXT_FALSE 0
#endif

#ifndef EXT_ENABLE
#define EXT_ENABLE 1
#define EXT_DISABLE 0
#endif

#define DIS 0
#define ENA 1
#define PRG 2
#define TOG 3

#define ENUM_STATE

	typedef enum
	{
		ST2_FAULSE = 0,
		ST2_TRUE = 1
	} lib_st2_type;

	typedef enum
	{
		ST3_FAULSE = -1,
		ST3_ZERO = 0,
		ST3_TRUE = 1,
	} lib_st3_type;

	typedef enum
	{
		OT2_DIS = 0,
		OT2_ENA = 1
	} lib_ot2_type;

	typedef enum
	{
		OT3_DIS = 0,
		OT3_ENA = 1,
		OT3_TOG = 2,
	} lib_ot3_type;
    
	typedef enum
	{
		EXE_ST_IDLE = 0,
		EXE_ST_EXEC = 1,
		EXE_ST_COMP = 2,
	} lib_exe_st_type;

	typedef enum
	{
		RS_CMD_IDLE = 0,
		RS_CMD_DIS, 
		RS_CMD_EN,
		RS_CMD_TOG,
		RS_CMD_SUSPEND,
		RS_CMD_RESUME,
		RS_CMD_SUSPEND_TOG,
	} lib_rs_cmd_req_type;
	
	typedef enum
	{
		DEV_ACT_IDLE = 0, 
		DEV_ACT_START,	  
		DEV_ACT_EXEC,	  
		DEV_ACT_COMP,	  
		DEV_ACT_FAIL,	  
	} lib_dev_act_step_type;

	typedef enum
	{
		STATE_REQ_NONE = 0x00, 
		STATE_REQ_EN = 0x01,  
		STATE_REQ_DIS = 0x02, 
		STATE_REQ_TOG = 0x03, 
	} state_req_type;
	
	typedef enum
	{
		RS_REQ_NONE = 0x00, 
		RS_REQ_START = 0x01,  
		RS_REQ_STOP = 0x02, 
		RS_REQ_TOG = 0x03, 
	} lib_rs_req_type;

	typedef enum
	{
		BISECT_MODE_EQ = 0, 
		BISECT_MODE_GE = 1, 
		BISECT_MODE_GT = 2, 
		BISECT_MODE_LT = 3, 
		BISECT_MODE_LE = 4, 
		BISECT_MODE_GE_LMT = 0x11, 
		BISECT_MODE_GT_LMT = 0x12, 
		BISECT_MODE_LT_LMT = 0x13, 
		BISECT_MODE_LE_LMT = 0x14, 
	}bisect_mode_type;

#define nKB(x) ((UU32)(x) << 10)
#define nMB(x) ((UU32)(x) << 20)
#define nGB(x) ((UU64)(x) << 30)
#define nTB(x) ((UU64)(x) << 40)
#define nPB(x) ((UU64)(x) << 50)
#define nEB(x) ((UU64)(x) << 60)
#define nZB(x) ((UU128)(x) << 70)
#define nYB(x) ((UU128)(x) << 80)

#define _KB_ ((UU32)(1) << 10)
#define _MB_ ((UU32)(1) << 20)
#define _GB_ ((UU32)(1) << 30)
#define _TB_ ((UU64)(1) << 40)
#define _PB_ ((UU64)(1) << 50)
#define _EB_ ((UU64)(1) << 60)
#define _ZB_ ((UU128)(1) << 70)
#define _YB_ ((UU128)(1) << 80)

#define LOG_TYPE_MASK 0x0F 
#define LOG_TYPE_HEAD 0x1  
#define LOG_TYPE_TAIL 0x3  
#define LOG_TYPE_DATA 0x2  
#define LOG_TYPE_EDIT 0x4  
#define LOG_TYPE_OPT 0x5   
#define LOG_TYPE_ALR 0x6   
#define LOG_TYPE_STAT 0x7  

#define LOG_FLAG_MASK 0xF0 
#define LOG_FLAG_NONE 0xF0

#define log_flag_type_make(flag, type) ((UU08)(((flag) & LOG_FLAG_MASK) | ((type) & LOG_TYPE_MASK)))
#define log_flag_make(flag) (~(UU08)((flag) & LOG_FLAG_MASK))
#define log_flag_get(fdat, flag) ((UU08)((~(fdat)) & (flag) & LOG_FLAG_MASK))
#define log_flag_merge(flag1, flag2) (~(UU08)((flag1) & (flag2) & LOG_FLAG_MASK))

#define LIBE_DEFINE

	typedef enum
	{
		LIBE_OK = 0,		  
		LIBE_PAR_VAL ,	  
		LIBE_PAR_LIMIT ,	  
		LIBE_PAR_LIMIT_L , 
		LIBE_PAR_LIMIT_H , 
		LIBE_RES_LIMIT ,	  
		LIBE_RES_LIMIT_L , 
		LIBE_RES_LIMIT_H , 
		LIBE_PRT_NULL ,	  
		LIBE_ADDRESS ,	  
		LIBE_LENGTH ,	  
		LIBE_VERIFY ,	  
		LIBE_TIME ,		  
		LIBE_PASSWORD ,	  
		LIBE_OPT_CODE ,	  
		LIBE_IC_CARD ,	  
		LIBE_FINGER ,	  
		LIBE_BIOINFO ,	  
		LIBE_LRC ,		  
		LIBE_CRC ,		  
		LIBE_MD5 ,		  
		LIBE_SHA ,		  
		LIBE_CPU ,		  
		LIBE_VERSION ,	  
		LIBE_LICENSE ,	  
		LIBE_ROM ,		  
		LIBE_SRAM ,		  
		LIBE_DRAM ,		  
		LIBE_POWER ,	  
		LIBE_IO ,		  
		LIBE_CLOCK ,	  
		LIBE_SITE_RANG ,  
		LIBE_FILE_OPEN ,  
		LIBE_FILE_READ ,  
		LIBE_FILE_WRITE , 
		LIBE_FILE_OTHER , 
		LIBE_OPT_RIGHTS , 
		LIBE_LOGIN ,	  
		LIBE_MEM_LESS ,	  
		LIBE_DATA_EMPTY , 
		LIBE_WRITE ,     
		LIBE_READ ,      
		LIBE_ERASE ,     
		LIBE_UNKNOWN ,   
	} LIBE_Type;

#ifndef __kernel

#ifndef offsetof
#define offsetof(TYPE, MEMBER) ((size_t)(&((TYPE *)0)->MEMBER))
#endif

#define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER))

#define offsetofend(TYPE, MEMBER) \
	(offsetof(TYPE, MEMBER) + sizeof_field(TYPE, MEMBER))

#ifndef SIZE_MAX
#define SIZE_MAX (~(size_t)0)
#endif

#ifndef U8_MAX
#define U8_MAX ((uu8)~0U)
#define S8_MAX ((ss8)(U8_MAX >> 1))
#define S8_MIN ((ss8)(-S8_MAX - 1))
#define U16_MAX ((uu16)~0U)
#define S16_MAX ((ss16)(U16_MAX >> 1))
#define S16_MIN ((ss16)(-S16_MAX - 1))
#define U32_MAX ((uu32)~0U)
#define U32_MIN ((uu32)0)
#define S32_MAX ((ss32)(U32_MAX >> 1))
#define S32_MIN ((ss32)(-S32_MAX - 1))
#define U64_MAX ((uu64)~0ULL)
#define S64_MAX ((ss64)(U64_MAX >> 1))
#define S64_MIN ((ss64)(-S64_MAX - 1))
#endif

#ifndef USHRT_MAX
#define USHRT_MAX ((unsigned short)~0U)
#define SHRT_MAX ((short)(USHRT_MAX >> 1))
#define SHRT_MIN ((short)(-SHRT_MAX - 1))
#define INT_MAX ((int)(~0U >> 1))
#define INT_MIN (-INT_MAX - 1)
#define UINT_MAX (~0U)
#define LONG_MAX ((long)(~0UL >> 1))
#define LONG_MIN (-LONG_MAX - 1)
#define ULONG_MAX (~0UL)
#define LLONG_MAX ((long long)(~0ULL >> 1))
#define LLONG_MIN (-LLONG_MAX - 1)
#define ULLONG_MAX (~0ULL)
#endif

#define is_power_of_2(n) (n != 0 && ((n & (n - 1)) == 0))
#define hex_asc_lo(x) hex_asc[((x) & 0x0f)]
#define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4]
	extern const char hex_asc[];

#endif

#define CC_LINE	__LINE__ 
#define CC_FILE	__FILE__ 
#define CC_DATE	__DATE__ 
#define CC_TIME	__TIME__ 

#ifdef __cplusplus
}
#endif

#endif 
